package controllers

import (
	//"github.com/astaxie/beego"
	 "web/models"
	 // "strconv"
)

type MainController struct {
	BaseController
}

func (c *MainController) Get() {
	index,err1 := c.GetInt("index")
	if err1 != nil{
		index = 1
	}
	cc, _ := models.ConnectSqlite()
	cc.InitDB()
	count := cc.Count()
	pre,next := index -1,index+1
	if pre < 1{
		pre =1
	} 
	if next > count{
		next =count
	}
	c.Data["Obj"] = cc.ReadOne(index)
	c.Data["Count"] = count
	c.Data["Index"] = index
	c.Data["Pre"] = pre
	c.Data["Next"] = next
    c.TplName = "img.tpl"
}

type UpController struct{
	BaseController
}

func (c *UpController) Get() {
	c.Ctx.WriteString("hello world")
}

func (c *UpController) Post() {
	id,_ := c.GetInt("id")
	tag := c.GetString("tag")
	info := c.GetString("info")
	height,_ := c.GetFloat("height")
	width,_ := c.GetFloat("width")
	top,_ := c.GetFloat("top")
	left,_ := c.GetFloat("left")
	h,w,t,l := int(height),int(width),int(top),int(left)

	cc, _ := models.ConnectSqlite()

	cc.Update(tag,info,t,l,w,h,id) 

	c.Ctx.WriteString("ok")
}
	// beego.Emergency("this is emergency")
	// beego.Alert("this is alert")
	// beego.Critical("this is critical")
	// beego.Error("this is error")
	// beego.Warning("this is warning")
	// beego.Notice("this is notice")
	// beego.Informational("this is informational")